﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using TileEngine.tiles;

namespace TileEngine.items.pickaxes
{
    class DefaultPickaxe:Defaultitem
    {
        int coolDown = 0;
        public override void mouseLeftClick(GameTime gameTime)
        {
            if (coolDown < getCoolDown())
            {
                coolDown += gameTime.ElapsedGameTime.Milliseconds;
                return;
            }
            Vector2 mouseTile = new Vector2(Mouse.GetState().X + Camera.Location.X, Mouse.GetState().Y + Camera.Location.Y);
            if ((mouseTile - Global.currentWorld.player.Location).Length() < 100)
            {
                if (Global.currentWorld.tiles[(int)mouseTile.X / Global.tileSize.X, (int)mouseTile.Y / Global.tileSize.Y].tile.GetType() != typeof(Empty))
                {
                    Global.currentWorld.tiles[(int)mouseTile.X / Global.tileSize.X, (int)mouseTile.Y / Global.tileSize.Y].tile.breakTile();
                    coolDown = 0;
                }

            }

        }
        public override void useDraw(SpriteBatch spriteBatch, Color tint)
        {
            spriteBatch.Draw(this.getTexture(), new Rectangle((int)Camera.screenDimension.X / 2, (int)Camera.screenDimension.Y / 2 - 3 * Global.tileSize.Y / 8, 30, 30), null, tint, (Global.currentWorld.player.isLookRight ? 1 : -1) *
                2*(float)coolDown / (float)getCoolDown(), new Vector2(25,50), Global.currentWorld.player.isLookRight ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
            spriteBatch.Draw(Textures.player, new Rectangle((int)Camera.screenDimension.X / 2, (int)Camera.screenDimension.Y / 2 - 3 * Global.tileSize.Y / 8, 7, 18), new Rectangle(393, 0, 7, 21), tint, (Global.currentWorld.player.isLookRight ? 1 : -1) *
                2 * (float)coolDown / (float)getCoolDown(), new Vector2(3.5f, Global.tileSize.X), SpriteEffects.None, 0);
        }
        int getCoolDown()//miliseconds
        {
            return 200;
        }
    }
}
